package com.epoint.mobileoa.adapter;

import java.util.List;
import java.util.Map;

import com.epoint.mobileoa.bizlogic.Res;
import com.epoint.mobileoa.bizlogic.SuperView;


import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class MailDraftAdp extends BaseAdapter {
	private LayoutInflater mInflater;
	List<Map<String, Object>> mData;
	private SuperView context;
	public MailDraftAdp(SuperView context, List<Map<String, Object>> mData) {
		this.mInflater = LayoutInflater.from(context);
		this.mData = mData;
		this.context = context;
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(Res.getLayoutInt("maillist"), null);
			holder.ml_mailimg = (ImageView) convertView
					.findViewById(Res.getIdInt("ml_mailimg"));
			holder.ml_attach = (ImageView) convertView
					.findViewById(Res.getIdInt("ml_attach"));
			holder.ml_mailtitle = (TextView) convertView
					.findViewById(Res.getIdInt("ml_mailtitle"));
			holder.ml_sandt = (TextView) convertView
					.findViewById(Res.getIdInt("ml_sandt"));

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.ml_mailimg.setBackgroundResource((Integer) mData.get(position)
				.get("mailimg"));
		String mtitle = (String) mData.get(position).get("mailtitle");
		holder.ml_mailtitle.setText(mtitle.equals("")?"(无标题)":mtitle);
		context.setTextViewFontColor(holder.ml_mailtitle);
		String time = (String) mData.get(position).get("mailsavetime");
		Spanned h = Html.fromHtml("<font color="+context.getYGColor()+">" + time
				+ "</font>");
		holder.ml_sandt.setText(h);
		return convertView;
	}

	class ViewHolder {
		public ImageView ml_mailimg;
		public ImageView ml_attach;
		public TextView ml_mailtitle;
		public TextView ml_sandt;
	}
}
